package com.test.nnooolwdeaer.dialog_wooden;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.activity_fragment_wooden.base_wooden.BaseActivity_wooden;
import com.test.nnooolwdeaer.util_wooden.StringUtil_wooden;
import com.test.nnooolwdeaer.util_wooden.http_wooden.HttpManager_wooden;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.test.nnooolwdeaer.adapter_wooden.WalletAccountTypeListAdapter_Cote_wooden;
import com.test.nnooolwdeaer.bean_wooden.StaticVariate_wooden;
import com.test.nnooolwdeaer.view_wooden.TrackEditText;


public class AddBankAccountDialog_Cote_wooden extends BottomSheetDialog {

    private BaseActivity_wooden baseActivity_wooden;
    private TextView prefix1Tv_wooden, prefix2Tv_wooden;
    private TrackEditText mobile1Et_wooden, mobile2Et_wooden;
    private Button submitBtn_wooden;
    private Button changeBtn_wooden;

    private ImageView accountTypeIv_wooden;
    private TextView accountTypeTv_wooden;

    private WalletAccountTypeListAdapter_Cote_wooden walletAccountTypeListAdapter_wooden;

    private String walletType_wooden = "WAVE";

    public static final String WalletType_Wave_wooden ="WAVE", WalletType_Others_wooden ="OTHERS";

    //提交按键点击事件
    private final View.OnClickListener submitBtnClickListener_wooden = v -> {
        String account1 = StringUtil_wooden.getSafeString_wooden(mobile1Et_wooden.gText());
        String account2 = StringUtil_wooden.getSafeString_wooden(mobile2Et_wooden.gText());
        HttpManager_wooden.getInstance_wooden().bindBankAccount_wooden(account1,account2, walletType_wooden);
        dismiss();
        saveBuriedPoint_wooden(true);
    };

    public AddBankAccountDialog_Cote_wooden(@NonNull Context context) {
        super(context, R.style.BottomSheetDialogStyle);
        if (context instanceof BaseActivity_wooden) baseActivity_wooden = (BaseActivity_wooden) context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_add_bank_account_cote_wooden);
        getWindow().setBackgroundDrawableResource(R.color.trans);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        init_wooden();
    }

    private void init_wooden(){

        prefix1Tv_wooden = findViewById(R.id.dialog_add_account_cote_tv_prefix_1);
        prefix2Tv_wooden = findViewById(R.id.dialog_add_account_cote_tv_prefix_2);
        mobile1Et_wooden = findViewById(R.id.dialog_add_account_cote_et_mobile_1);
        mobile2Et_wooden = findViewById(R.id.dialog_add_account_cote_et_mobile_2);
        submitBtn_wooden = findViewById(R.id.dialog_add_account_cote_btn_submit);
        changeBtn_wooden = findViewById(R.id.dialog_add_account_cote_btn_change);
        accountTypeIv_wooden = findViewById(R.id.dialog_add_account_cote_iv_account_type);
        accountTypeTv_wooden = findViewById(R.id.dialog_add_account_cote_tv_account_type);

        mobile1Et_wooden.sTrackWord("ADD_ACCOUNT_DIALOG_ACCOUNT_1_INPUT");
        mobile2Et_wooden.sTrackWord("ADD_ACCOUNT_DIALOG_ACCOUNT_2_INPUT");

        String prefix = StaticVariate_wooden.getMobilePrefix_wooden();
        prefix1Tv_wooden.setText(prefix);
        prefix2Tv_wooden.setText(prefix);

        changeBtn_wooden.setOnClickListener(v -> changeType_wooden());

        findViewById(R.id.dialog_add_bank_account_cote_ib_back).setOnClickListener(v -> {
            dismiss();
            saveBuriedPoint_wooden(false);
        });

        submitBtn_wooden.setOnClickListener(submitBtnClickListener_wooden);

    }

    @SuppressLint("SetTextI18n")
    @Override
    public void show() {
        super.show();
        if (walletType_wooden.equalsIgnoreCase(WalletType_Wave_wooden)) HttpManager_wooden.getInstance_wooden().saveUserBuriedPoint("ADD_ACCOUNT_DIALOG_WAVE_COTE_START");
        else HttpManager_wooden.getInstance_wooden().saveUserBuriedPoint("ADD_ACCOUNT_DIALOG_OTHERS_COTE_START");
    }


    //上传埋点
    private void saveBuriedPoint_wooden(boolean isSubmitBtn){
        if (isSubmitBtn)
            HttpManager_wooden.getInstance_wooden().saveUserBuriedPoint("ADD_ACCOUNT_DIALOG_SUBMIT_CLICK");
        else
            HttpManager_wooden.getInstance_wooden().saveUserBuriedPoint("ADD_ACCOUNT_DIALOG_CANCEL_CLICK");

    }

    @SuppressLint("SetTextI18n")
    public void changeType_wooden(){
        if (walletType_wooden.equalsIgnoreCase(WalletType_Wave_wooden)){
            walletType_wooden = WalletType_Others_wooden;
            accountTypeIv_wooden.setBackgroundResource(R.drawable.icon_cote_wallet_type_others);
            accountTypeTv_wooden.setText("Orange/MTN/MOOV");
            changeBtn_wooden.setText("Je veux utiliser Wave");
            HttpManager_wooden.getInstance_wooden().saveUserBuriedPoint("ADD_ACCOUNT_DIALOG_OTHER_COTE_START");
        }else{
            walletType_wooden = WalletType_Wave_wooden;
            accountTypeIv_wooden.setBackgroundResource(R.drawable.icon_cote_wallet_type_wave);
            accountTypeTv_wooden.setText("Wave");
            changeBtn_wooden.setText("je n'ai pas Wave");
            HttpManager_wooden.getInstance_wooden().saveUserBuriedPoint("ADD_ACCOUNT_DIALOG_WAVE_COTE_START");
        }
    }

    @Override
    public void dismiss() {
        super.dismiss();
        if (walletType_wooden.equalsIgnoreCase(WalletType_Wave_wooden)) HttpManager_wooden.getInstance_wooden().saveUserBuriedPoint("ADD_ACCOUNT_DIALOG_WAVE_COTE_END");
        else HttpManager_wooden.getInstance_wooden().saveUserBuriedPoint("ADD_ACCOUNT_DIALOG_OTHERS_COTE_END");
    }
}
